#	Copyright (C) 2008 Sambit Bikas Pal, IISERK
#	Author: Sambit Bikas Pal , Email: sam@botcyb.org , sambit@iiserkol.ac.in
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
__author__ = 'Sambit Bikas Pal'

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

import feed				#Fetches the feeds burnt by Google Feedburner
from editable import iiserk		#IISERK -ke niye bhaat boka achhe
from editable import linkbox		#Contains links
from editable import heads		#Contains stuffs to be inserted in heads of various pages
from editable import feet		#Contains stuffs to be put at the end of various pages

class HomePage(webapp.RequestHandler):

	def collect(self):
		iiserkfeed = feed.feedfetch()			#Fetches the notices
		self.notices = iiserkfeed.getfeed(("http://feedproxy.google.com/Iiserk?format=sigpro"))
		iiserkabout = iiserk.iiserk()			#Fetches the jabbering about IISERK
		self.about = iiserkabout.BHATER_CHOP
		links = linkbox.links()				#Fetches the linkbox
		self.links = links.LINK_BOX
		head = heads.heads()				#Fetches the heads
		self.head = head.HOME_PAGE
		foot = feet.feet()				#Fetches the feet
		self.foot = foot.HOME_PAGE


	def create_html(self):					#Creates the homepage
		self.html = """
			<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
			<html xmlns="http://www.w3.org/1999/xhtml">
			""" + self.head + """
			<body>
			<div id="content">
			<div id="header"><h1>iiser kolkata <span class="smaller">unofficial site</span></h1></div>
			""" + self.notices + self.about + self.links + """
			</div>
			""" + self.foot + """
			</body>
			</html>
			"""

	def get(self):
		self.collect()						#Calls collect to collect stuffs
		self.create_html()					#Generates the HTML

		self.response.headers['Content-Type'] = 'text/html'
		self.response.out.write(self.html)			#Spews out the page


home = webapp.WSGIApplication([('/', HomePage)])

def main():
	run_wsgi_app(home)

if __name__ == "__main__":
	main()
